package com.lzc.product.controller;

import com.lzc.Util;
import com.lzc.product.model.ShoppingCar;
import com.lzc.product.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/getCar.do")
public class ShoppingCarInfoServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//         获取session对象并且拿session对象中的会员编号
        Object cId = req.getSession().getAttribute("customerId");
//        如果用户编号为空
        if (cId == null) {
//            跳转登录页面
            Util.writerData(resp,new ArrayList());
            return ;
        }
//        将会员编号转换为字符串类型
        String customerId = cId.toString();
        ProductService productService = new ProductService();
        List<ShoppingCar>list= productService.getShoppingCarInfo(customerId);
        Util.writerData(resp,list);
    }
}